/*
	Travis Tarr
	CS362-400
	
	Assignment #3
	
	Testing the gainCard() function
		int gainCard(int supplyPos, struct gameState *state, int toFlag, int player)
	
*/

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

void testGainCard() {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;

	int deckCount, discardCount;

    printf ("TESTING gainCard():\n");
    for (p = 0; p < numPlayer; p++)
    {
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {

			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			G.handCount[p] = handCount;                 // set the number of cards on hand
			
			// card to discard (toFlag == 0)
			discardCount = G.discardCount[p];
			if(gainCard(copper, &G, 0, p) == 1) {
				assert(G.discardCount[p] == discardCount + 1);
				printf("gainCard(): PASSED when adding card to discard pile\n");
			} else {
				printf("gainCard(): FAILED when adding card to discard pile\n");
			}
			
			// card to deck (toFlag == 1)
			deckCount = G.deckCount[p];
			if(gainCard(copper, &G, 1, p) == 1) {
				assert(G.deckCount[p] == deckCount + 1);
				printf("gainCard(): PASSED when adding card to deck\n");
			} else {
				printf("gainCard(): FAILED when adding card to deck\n");
			}
			
			// card to hand (toFlag == 2)
			if(gainCard(copper, &G, 2, p) == 1) {
				assert(G.handCount[p] == handCount + 1);
				printf("gainCard(): PASSED when adding card to hand\n");
			} else {
				printf("gainCard(): FAILED when adding card to hand\n");
			}

		}
		
	}
		
	
}

int main() {
	testGainCard();
	return 0;
}